﻿#include"msave.h"
#include<stddef.h>
#include<malloc.h>
MValue MCreateValue(int size)
{
	MValue re;
	re.value = NULL;
	re.len = size;
	return re;
}
bool MMallocValue(int size, MValue* val)
{
	if (val == NULL)
		return false;
	val->value = malloc(size);
	val->len = size;
	return true;
}
void MDeletValue(MValue* val)
{
	free(val->value);
	val->len = 0;
}
bool MSetValue(void* buf, MValue* val)
{
	void* n = buf;
	if (val == NULL)
		return false;
	if (val->len <= sizeof(buf))
	{
		//先扩容
		free(val->value);
		val->value = malloc(sizeof(buf));
		if (val->value == NULL)
			return false;
	}
	val->value = n;
	return true;
}
MStack MCreateStack(int size)
{
	MStack ms;
	ms.ps = 0;
	ms.size = size;
	ms.stack = (int*)malloc(sizeof(int) * size);
	return ms;
}
